<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <!--引入elementui得样式-->
    <link type="text/css" rel="stylesheet" href="/css/index.css"/>
    <!--引入vue得依赖必须再elementui之前引入vue-->
    <script type="text/javascript" src="/js/vue.js"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script type="text/javascript" src="/js/qs.min.js"></script>
</head>
<body>
<div id="app">
    <el-form ref="loginForm" :model="loginForm" label-width="80px">
        <el-form-item label="用户名" prop="username">
            <el-input v-model="loginForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
    </el-form>
</div>


</body>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            loginForm: {
                username: '',
                password: ''
            }
        },
        methods: {
            login: function() {
                this.$refs.loginForm.validate((valid) => {
                    if (valid) {
                        axios.post('/root/login', this.loginForm).then(response => {
                            if (response.data.code===2000) {
                                this.$message({message: response.data.msg, type: 'success'});
                                window.location.href = 'root.html';
                            } else {
                                this.$message.error(response.data.msg);
                            }
                        }).catch(error => {
                            console.error(error);
                            this.$message.error("登录失败");
                        });
                    } else {
                        console.log('验证失败');
                        return false;
                    }
                });
            }
        }
    });
</script>
</html>
